﻿Imports System.Data.SqlClient
Public Class frmHangHoa
    Private Sub CapNhatLuoi()
        Dim strSql As String = "select ROW_NUMBER() OVER (ORDER BY hh.MaHH) as STT, hh.MaHH as [Mã hàng hóa], hh.TenHH as [Tên hàng hóa], dv.TenDV as [Đơn vị tính], hh.DienGiai as [Diễn giải], hh.MaDV from HangHoa hh left join DonVi dv on dv.MaDV = hh.MaDV "
        Dim myConn As New SqlConnection(modKetNoi.strConnectionString)
        Dim myTable As New DataTable
        Try
            myConn.Open()
            If txtKey.Text <> "" Then
                If radMaHH.Checked = True Then
                    strSql &= " Where hh.MaHH = '" & txtKey.Text & "'"
                Else
                    strSql &= " Where hh.TenHH like N'%" & txtKey.Text & "%'"
                End If
            End If
            strSql &= " order by STT"
            Dim myAdapter As New SqlDataAdapter(strSql, myConn)
            myAdapter.Fill(myTable)
            dgvList.DataSource = myTable
            dgvList.Columns.Item(0).Width = 50
            dgvList.Columns.Item(1).Width = 100
            dgvList.Columns.Item(2).Width = 300
            dgvList.Columns.Item(3).Width = 100
            dgvList.Columns.Item(4).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            dgvList.Columns.Item(5).Visible = False
        Catch ex As Exception

        End Try
        myConn.Close()
        myConn.Dispose()
    End Sub

    Private Sub btnTim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTim.Click
        CapNhatLuoi()
    End Sub

    Private Sub btnDong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDong.Click
        Me.Close()
    End Sub

    Private Sub frmHangHoa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CapNhatLuoi()
    End Sub
End Class